package com.xingkeduo.json;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xingkeduo.dto.wxma.WxJsApiDto;
import com.xingkeduo.util.pojo.base.BaseJson;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/4/22 20:14
 **/
public class BaseDTOJTO extends BaseJson {


    /**
     * 处理成功返回json格式的数据
     *
     * @param content
     * @return
     */
    public static ObjectNode toSuccessJson(ObjectNode content) {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "0");
        root.put("content", content);
        return root;
    }


    /**
     * 处理失败返回json格式的数据
     *
     * @param content
     * @return
     */
    public static ObjectNode toErrorJson(String reason) {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", -1);
        root.put("reason", reason);
        root.put("content", "");
        return root;
    }
    /**
     * 处理失败返回json格式的数据
     *
     * @param content
     * @return
     */
    public static ObjectNode toUserAuthError(String code) {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", code);
        root.put("reason", "用户信息更新中 请等待");
        root.put("content", "用户信息更新中 请等待");
        return root;
    }

    public static ObjectNode toJsonForCheck_new_user_coupon() {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "0");
        root.put("content", false);
        return root;
    }

    public static ObjectNode toJsonForCheck_store_list_modal() {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "0");
        ObjectNode content = MAPPER.createObjectNode();
        content.put("steward_modal", false);
        root.put("content", content);
        return root;
    }

    public static ObjectNode toJsonForSteward_qrcode() {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "0");
        ObjectNode content = MAPPER.createObjectNode();
        content.put("qrcode_url", "https://imgcdn.xingkeduo.com/custom_service_qrcode/2019/04-26/ed3589e0ab53fcc022774e5e317f65e1.jpg");
        root.put("content", content);
        return root;
    }

    public static ObjectNode toJsonForCheck_store_detail_modal() {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 2);
        root.put("reason", "没有活动");
        ObjectNode content = MAPPER.createObjectNode();
        root.put("content", content);
        return root;
    }

    public static ObjectNode toJsonForCheck_order_detail_modal() {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "0");
        root.put("content", false);
        return root;
    }


    public static ObjectNode toJsonForCheckModal() {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "0");
        root.put("content", "星客多送您一张Barber剪发券，希望您常来哦！快去个人中心查看");
        return root;
    }
    /**
     * 小程序code
     *
     * @param :
     * @return : com.fasterxml.jackson.databind.node.ObjectNode
     * @author : gaozifeng
     * @date : 2019/5/8 17:55
     */
    public static ObjectNode toJsonCode(String seesionKey) {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "1000");
        root.put("msg", "SUCCESS");
        root.put("html", seesionKey);
        return root;
    }

    /**
     * 小程序code
     *
     * @param :
     * @return : com.fasterxml.jackson.databind.node.ObjectNode
     * @author : gaozifeng
     * @date : 2019/5/8 17:55
     */
    public static ObjectNode toJsonSuccess() {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "0");
        root.put("msg", "SUCCESS");
        return root;
    }

    /**
     * 小程序code
     *
     * @param :
     * @return : com.fasterxml.jackson.databind.node.ObjectNode
     * @author : gaozifeng
     * @date : 2019/5/8 17:55
     */
    public static ObjectNode toWxTicket(WxJsApiDto dto) {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", "0");
        root.putPOJO("content", toJson(dto));
        return root;
    }

    public static ObjectNode toJson(WxJsApiDto dto) {
        ObjectNode root = MAPPER.createObjectNode();

        if (null != dto) {
            root.putPOJO("jssdk", dto);
        }
        return root;
    }

    public static ObjectNode error() {
        ObjectNode root = MAPPER.createObjectNode();
        ObjectNode msg = MAPPER.createObjectNode();
        root.put("error", 0);
        root.put("reason", 0);
        msg.putPOJO("msg","服务器维护中，预计将持续到0:30，谢谢您的关注");
        root.putPOJO("content", msg);
        return root;
    }

    public static ObjectNode serviceUpdate() {
        ObjectNode root = MAPPER.createObjectNode();
        root.put("error", 10000);
        root.put("reason", "服务器升级中，暂时无法进行操作。");
        root.putPOJO("content", "");
        return root;
    }

}
